package com.yicun.HttpUtils;

import java.io.File;
import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;

/* loaded from: classes.dex */
public class DownloadUtil {
    private static DownloadUtil downloadUtil;
    private final OkHttpClient okHttpClient = new OkHttpClient();

    public interface OnDownloadListener {
        void onDownloadFailed(Exception exc);

        void onDownloadSuccess(File file);

        void onDownloading(int i);
    }

    public static DownloadUtil get() {
        if (downloadUtil == null) {
            downloadUtil = new DownloadUtil();
        }
        return downloadUtil;
    }

    public void download(String str, final String str2, final String str3, final OnDownloadListener onDownloadListener) {
        Request build = new Request.Builder().url(str).build();
        try {
            new OkHttpClient().newCall(build).execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        this.okHttpClient.newCall(build).enqueue(new Callback() { // from class: com.example.MoJuGuiDingZhi.HttpUtils.DownloadUtil.1
            @Override // okhttp3.Callback
            public void onFailure(Call call, IOException iOException) {
                onDownloadListener.onDownloadFailed(iOException);
            }

            /* JADX WARN: Removed duplicated region for block: B:35:0x008a A[Catch: IOException -> 0x008d, TRY_LEAVE, TryCatch #6 {IOException -> 0x008d, blocks: (B:40:0x0085, B:35:0x008a), top: B:39:0x0085 }] */
            /* JADX WARN: Removed duplicated region for block: B:39:0x0085 A[EXC_TOP_SPLITTER, SYNTHETIC] */
            @Override // okhttp3.Callback
            /*
                Code decompiled incorrectly, please refer to instructions dump.
                To view partially-correct code enable 'Show inconsistent code' option in preferences
            */
            public void onResponse(okhttp3.Call r10, okhttp3.Response r11) throws IOException {
                /*
                    r9 = this;
                    r10 = 2048(0x800, float:2.87E-42)
                    byte[] r10 = new byte[r10]
                    java.io.File r0 = new java.io.File
                    java.lang.String r1 = r3
                    r0.<init>(r1)
                    boolean r1 = r0.exists()
                    if (r1 != 0) goto L14
                    r0.mkdirs()
                L14:
                    java.io.File r1 = new java.io.File
                    java.lang.String r2 = r4
                    r1.<init>(r0, r2)
                    r0 = 0
                    okhttp3.ResponseBody r2 = r11.body()     // Catch: java.lang.Throwable -> L6f java.lang.Exception -> L72
                    java.io.InputStream r2 = r2.byteStream()     // Catch: java.lang.Throwable -> L6f java.lang.Exception -> L72
                    okhttp3.ResponseBody r11 = r11.body()     // Catch: java.lang.Throwable -> L67 java.lang.Exception -> L6b
                    long r3 = r11.contentLength()     // Catch: java.lang.Throwable -> L67 java.lang.Exception -> L6b
                    java.io.FileOutputStream r11 = new java.io.FileOutputStream     // Catch: java.lang.Throwable -> L67 java.lang.Exception -> L6b
                    r11.<init>(r1)     // Catch: java.lang.Throwable -> L67 java.lang.Exception -> L6b
                    r5 = 0
                L33:
                    int r0 = r2.read(r10)     // Catch: java.lang.Throwable -> L63 java.lang.Exception -> L65
                    r7 = -1
                    if (r0 == r7) goto L52
                    r7 = 0
                    r11.write(r10, r7, r0)     // Catch: java.lang.Throwable -> L63 java.lang.Exception -> L65
                    long r7 = (long) r0     // Catch: java.lang.Throwable -> L63 java.lang.Exception -> L65
                    long r5 = r5 + r7
                    float r0 = (float) r5     // Catch: java.lang.Throwable -> L63 java.lang.Exception -> L65
                    r7 = 1065353216(0x3f800000, float:1.0)
                    float r0 = r0 * r7
                    float r7 = (float) r3     // Catch: java.lang.Throwable -> L63 java.lang.Exception -> L65
                    float r0 = r0 / r7
                    r7 = 1120403456(0x42c80000, float:100.0)
                    float r0 = r0 * r7
                    int r0 = (int) r0     // Catch: java.lang.Throwable -> L63 java.lang.Exception -> L65
                    com.example.MoJuGuiDingZhi.HttpUtils.DownloadUtil$OnDownloadListener r7 = r2     // Catch: java.lang.Throwable -> L63 java.lang.Exception -> L65
                    r7.onDownloading(r0)     // Catch: java.lang.Throwable -> L63 java.lang.Exception -> L65
                    goto L33
                L52:
                    r11.flush()     // Catch: java.lang.Throwable -> L63 java.lang.Exception -> L65
                    com.example.MoJuGuiDingZhi.HttpUtils.DownloadUtil$OnDownloadListener r10 = r2     // Catch: java.lang.Throwable -> L63 java.lang.Exception -> L65
                    r10.onDownloadSuccess(r1)     // Catch: java.lang.Throwable -> L63 java.lang.Exception -> L65
                    if (r2 == 0) goto L5f
                    r2.close()     // Catch: java.io.IOException -> L81
                L5f:
                    r11.close()     // Catch: java.io.IOException -> L81
                    goto L81
                L63:
                    r10 = move-exception
                    goto L69
                L65:
                    r10 = move-exception
                    goto L6d
                L67:
                    r10 = move-exception
                    r11 = r0
                L69:
                    r0 = r2
                    goto L83
                L6b:
                    r10 = move-exception
                    r11 = r0
                L6d:
                    r0 = r2
                    goto L74
                L6f:
                    r10 = move-exception
                    r11 = r0
                    goto L83
                L72:
                    r10 = move-exception
                    r11 = r0
                L74:
                    com.example.MoJuGuiDingZhi.HttpUtils.DownloadUtil$OnDownloadListener r1 = r2     // Catch: java.lang.Throwable -> L82
                    r1.onDownloadFailed(r10)     // Catch: java.lang.Throwable -> L82
                    if (r0 == 0) goto L7e
                    r0.close()     // Catch: java.io.IOException -> L81
                L7e:
                    if (r11 == 0) goto L81
                    goto L5f
                L81:
                    return
                L82:
                    r10 = move-exception
                L83:
                    if (r0 == 0) goto L88
                    r0.close()     // Catch: java.io.IOException -> L8d
                L88:
                    if (r11 == 0) goto L8d
                    r11.close()     // Catch: java.io.IOException -> L8d
                L8d:
                    throw r10
                */
                throw new UnsupportedOperationException("Method not decompiled: com.example.MoJuGuiDingZhi.HttpUtils.DownloadUtil.C04961.onResponse(okhttp3.Call, okhttp3.Response):void");
            }
        });
    }
}